﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Oracle.DataAccess.Client;
using ERP.Source.DBBridge;

namespace ERP.Source.Core
{
    public class User
    {
        private string username;
        private string password;

        private UserDetail userDetail;

        public string Username
        {
            set
            {
                username = value;
            }
            get
            {
                return username;
            }
        }

        public string Password
        {
            set
            {
                password = value;
            }
            get
            {
                return password;
            }
        }

        public UserDetail UserDetail
        {
            set 
            {
                userDetail = value;
            }
            get 
            {
                return userDetail;
            }
        }

        public bool Login()
        {
            string strsql = "Select * from NHANSU where USERNAME = '" + username + "'";

            OracleCommand oc = new OracleCommand(strsql, Database.Conn);
            OracleDataReader odr = oc.ExecuteReader();
            if (odr.Read())
            {
                string pwd = odr["PASS"].ToString();
                if (String.Compare(pwd, password) == 0)
                {
                    return true;
                }
            }

            odr.Dispose();
            oc.Dispose();

            return false;
        }

        public short SetLevel()
        {
            //tra ve cap bac tuy thuoc vao nguoi su dung
            //tuy thuoc gia tri position ma quy dinh cap bac
            //co tat ca 4 cap bac

            return 1;
        }

        public void SetUserDetail()
        {
            userDetail = new UserDetail();
            userDetail.SetUserDetail(this);
        }
    }
}
